package com.anolesoft.amljmes.foreknow.controller;

import com.anolesoft.amljmes.foreknow.bo.MesBzzPtdmx;
import com.anolesoft.amljmes.foreknow.dto.MesBzzPtdDto;
import com.anolesoft.amljmes.foreknow.service.MesBzzPtdService;
import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mesbzzptd")
public class MesBzzPtdController {

    @Autowired
    private MesBzzPtdService service;

    @RequestMapping(value = "/query" , method = RequestMethod.POST)
    public AjaxResult queryMesBzzPtjhInfo(@RequestBody MesBzzPtdDto dto){
        Integer pageNum = dto.getPageNum();
        Integer pageSize = dto.getPageSize();
        LoginUser loginUser = com.anolesoft.yr.util.SecurityUtils.getLoginUser();
        MesBzzPtdDto mesBzzPtdDto = new MesBzzPtdDto();
        mesBzzPtdDto.setFactoryCode(loginUser.getFacCode());
        if (dto.getSupportingOrderNo() != null){
            mesBzzPtdDto.setSupportingOrderNo(dto.getSupportingOrderNo().trim());
        }
        if (dto.getOrderNumber() != null){
            mesBzzPtdDto.setOrderNumber(dto.getOrderNumber().trim());
        }

        List<MesBzzPtdmx> allList = service.query(mesBzzPtdDto);
        int endIndex = pageNum * pageSize > allList.size() ? allList.size() : pageNum * pageSize;
        List<MesBzzPtdmx> list = allList.subList( (pageNum-1) *pageSize, endIndex);
        PageResult pageResult = new PageResult(list, pageSize, pageNum, allList.size());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,pageResult);
    }
}
